package thread;

/**
 * 主线程（main）
 * 线程提供了一个静态方法:
 * static Thread currentThread()
 * 该方法可以获取运行这个方法的线程，后期学习ThreadLocal这个类时会用到它
 */
public class CurrentThreadDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();
        System.out.println("主线程："+main);
        doSome();

        Thread t = new Thread(){
            public void run(){
                Thread t = Thread.currentThread();
                System.out.println("自定义线程："+t);
                doSome();
            }
        };
        t.start();
    }

    public static void doSome(){
        Thread t = Thread.currentThread();
        System.out.println("运行doSome方法的线程是："+t);
    }
}
